package com.thuanpq60023.easyenglish.activity;

import com.thuanpq60023.easyenglish.R;
import com.thuanpq60023.easyenglish.entity.VocabEntity;
import com.thuanpq60023.easyenglish.helper.GlobalFont;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListActivityAdapter extends BaseAdapter {
	private VocabEntity[] mEntities;
	private LayoutInflater mInflater;
	private Typeface font;

	public ListActivityAdapter(VocabEntity[] entity, Context context) {
		this.mEntities = entity;
		mInflater = LayoutInflater.from(context);
		font = new GlobalFont(context).getUVNBanTay();
	}

	@Override
	public int getCount() {
		return mEntities.length;
	}

	@Override
	public VocabEntity getItem(int position) {
		// TODO Auto-generated method stub
		return mEntities[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.list_layout_item, null);
			holder = new ViewHolder();
			holder.tvNo = (TextView) convertView
					.findViewById(R.id.list_layout_item_number);
			holder.tvNo.setTypeface(font);
			holder.tvType = (TextView) convertView
					.findViewById(R.id.list_layout_item_type);
			holder.tvType.setTypeface(font);
			holder.tvWord = (TextView) convertView
					.findViewById(R.id.list_layout_item_word);
			holder.tvWord.setTypeface(font);
			convertView.setTag(holder);

		} else {
			// Get the ViewHolder back to get fast access to the TextView
			holder = (ViewHolder) convertView.getTag();
		}
		// Bind the data with the holder.
		holder.tvType.setText(mEntities[position].getType());
		holder.tvWord.setText(mEntities[position].getWord());
		holder.tvNo.setText(Integer.toString(position));

		return convertView;
	}

	public static class ViewHolder {
		public TextView tvNo;
		public TextView tvType;
		public TextView tvWord;
	}
}
